import { get, post, put, del } from '@/utils/http/request'
import { mockGet } from '@/utils/http/request-mock'
import { R, P } from '@/utils/http/type'

import {
  MenuDetailAndButtonPermission,
  AddUpdateShopAdminPermission,
  MenuTree,
} from './types/menu'
export * from './types/menu'

/**
 * 添加菜单/权限
 */
export const getUserButtonPermission = () => {
  return get<R<string[]>>('/user/role/permission/relation/buttons')
}

/**
 * 添加菜单/权限
 */
export const getMenuTree = () => {
  return get<R<MenuTree[]>>('/permission/menu/tree')
}

/**
 * 添加菜单/权限
 */
export const deleteShopAdminPermission = (id: number) => {
  return del(`/permission/${id}`)
}

/**
 * 添加菜单/权限
 */
export const addShopAdminPermission = (data: AddUpdateShopAdminPermission) => {
  return post('/permission', data)
}

/**
 * 获取菜单详情及其按钮权限
 * @param id 权限id
 */
export const getMenuDetailAndButtonPermission = (id: number) => {
  return get<R<MenuDetailAndButtonPermission>>(`/permission/detail/${id}`)
}

import type { RouteRecordNormalized } from 'vue-router'
export const getMenuList = (): R<RouteRecordNormalized[]> => {
  return mockGet('/api/user/menu')
}
